package api

import (
	"server/global"
	"server/model/common/response"
	"server/plugin/mall/model"
	"server/plugin/mall/model/request"
	"server/plugin/mall/service"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

var A商品sku = new(shangpinsku)

type shangpinsku struct{}

// CreateA商品sku 创建商品sku
// @Tags A商品sku
// @Summary 创建商品sku
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A商品sku true "创建商品sku"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /shangpinsku/createA商品sku [post]
func (a *shangpinsku) CreateA商品sku(c *gin.Context) {
	var info model.A商品sku
	err := c.ShouldBindJSON(&info)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = service.A商品sku.CreateA商品sku(&info)
	if err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("创建成功", c)
}

// DeleteA商品sku 删除商品sku
// @Tags A商品sku
// @Summary 删除商品sku
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A商品sku true "删除商品sku"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /shangpinsku/deleteA商品sku [delete]
func (a *shangpinsku) DeleteA商品sku(c *gin.Context) {
	ID := c.Query("ID")
	err := service.A商品sku.DeleteA商品sku(ID)
	if err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteA商品skuByIds 批量删除商品sku
// @Tags A商品sku
// @Summary 批量删除商品sku
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /shangpinsku/deleteA商品skuByIds [delete]
func (a *shangpinsku) DeleteA商品skuByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := service.A商品sku.DeleteA商品skuByIds(IDs)
	if err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateA商品sku 更新商品sku
// @Tags A商品sku
// @Summary 更新商品sku
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A商品sku true "更新商品sku"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /shangpinsku/updateA商品sku [put]
func (a *shangpinsku) UpdateA商品sku(c *gin.Context) {
	var info model.A商品sku
	err := c.ShouldBindJSON(&info)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = service.A商品sku.UpdateA商品sku(info)
	if err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindA商品sku 用id查询商品sku
// @Tags A商品sku
// @Summary 用id查询商品sku
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query model.A商品sku true "用id查询商品sku"
// @Success 200 {object} response.Response{data=model.A商品sku,msg=string} "查询成功"
// @Router /shangpinsku/findA商品sku [get]
func (a *shangpinsku) FindA商品sku(c *gin.Context) {
	ID := c.Query("ID")
	reshangpinsku, err := service.A商品sku.GetA商品sku(ID)
	if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(reshangpinsku, c)
}

// GetA商品skuList 分页获取商品sku列表
// @Tags A商品sku
// @Summary 分页获取商品sku列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.A商品skuSearch true "分页获取商品sku列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /shangpinsku/getA商品skuList [get]
func (a *shangpinsku) GetA商品skuList(c *gin.Context) {
	var pageInfo request.A商品skuSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := service.A商品sku.GetA商品skuInfoList(pageInfo)
	if err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败:"+err.Error(), c)
		return
	}
	response.OkWithDetailed(response.PageResult{
		List:     list,
		Total:    total,
		Page:     pageInfo.Page,
		PageSize: pageInfo.PageSize,
	}, "获取成功", c)
}

// GetA商品skuPublic 不需要鉴权的商品sku接口
// @Tags A商品sku
// @Summary 不需要鉴权的商品sku接口
// @accept application/json
// @Produce application/json
// @Param data query request.A商品skuSearch true "分页获取商品sku列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /shangpinsku/getA商品skuPublic [get]
func (a *shangpinsku) GetA商品skuPublic(c *gin.Context) {
	// 此接口不需要鉴权 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
	service.A商品sku.GetA商品skuPublic()
	response.OkWithDetailed(gin.H{"info": "不需要鉴权的商品sku接口信息"}, "获取成功", c)
}
